#!/bin/bash

PATCH_DIR=patches
TOP=$2

if [ 0 == 1 ] ; then
#skip some projects include binary files. we replace the whole project codes directly.
if [ `pwd` = "$2/device/intel/firmware" ] ; then
	echo "skip device/intel/firmware ... "
	exit
fi
fi

if [ `git diff $1 2>/dev/null | wc -l` -gt 0 ] ; then

	echo create patch: $REPO_PROJECT
	strNum=`echo $2|wc -m`
	strNum=`expr $strNum + 1`
	projPath=`pwd | cut -c $strNum-`

	mkdir -p $TOP/$PATCH_DIR/$projPath
	git diff --binary $1 2>/dev/null > $TOP/$PATCH_DIR/$projPath/`echo $REPO_PROJECT.patch|sed "s/\//_/g"`
	
#	NUM=`grep "GIT binary patch" *.patch | wc -l` 
#	if [ "$NUM" != "0" ] ; then
#		echo "this patch contains binary files. Let's replace codes for update!"
#		echo $2
#		#tar -rvf $2.tar  --exclude-.git
#	fi

	echo ""
fi
